#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main()
{
	int n;
	while (cin >> n)
	{
		vector<int> arr(n);
		for (int i = 0; i < n;i++)
		{
			cin >> arr[i];
		}
		int count = 0;
		for (int i = 0; i < n - 1; i++)
		{
			vector<int>::iterator Max = max_element(arr.begin(), arr.end()-i);
			if (Max == (arr.end() - i - 1)) continue;
			if (Max != arr.begin())
			{
				count+=2;
				string str;
				reverse(arr.begin(), Max+1);
				reverse(arr.begin(), (arr.end()-i));
			}
			else
			{
				count++;
				reverse(arr.begin(), (arr.end() - i));
			}
		}
		cout << count << endl;
	}
	return 0;
}
